package com.yongchun.pubInter;

import lombok.Data;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Criteria;

import java.util.List;

/**
 * @author afeng
 * @version 1.0
 * @date 2022/8/29 下午10:51
 */
@Data
public abstract class BaseSearch extends Criteria implements Pageable {


    private static final long serialVersionUID = 1L;
    private List idIn;
    private String orderBy = "";
    private String orderDesc = "desc";
    /**
     * 当前页
     */

    private int pageNumber = 1;
    /**
     * 页大小
     */

    private int pageSize = 20;

   // private List<AggregationOperation> matchOperationList = new SkList<>();



    /*public void addMatchOperation(Criteria criteria) {

        matchOperationList.add(Aggregation.match(criteria));
    }*/


    public com.yongchun.pubInter.BaseSearch setIdIn(List idIn) {
        this.idIn = idIn;
        and(getIdFiled()).in(idIn);
     //   addMatchOperation(Criteria.where(getIdFiled()).in(idIn));

        return this;
    }

    public abstract String getIdFiled();

    public com.yongchun.pubInter.BaseSearch setOrderBy(String orderBy) {
        if (orderBy == null || "".equalsIgnoreCase(orderBy)) {
            return this;
        }
        this.orderBy = orderBy;



        return this;
    }







    @Override
    public long getOffset() {
        return (getPageNumber() - 1) * getPageSize();
    }







    @Override
    public Sort getSort() {




        if (orderDesc.equalsIgnoreCase("asc")) {
            return Sort.by(Sort.Direction.ASC, orderBy);
        } else {
            return Sort.by(Sort.Direction.DESC, orderBy);

        }


    }

    @Override
    public Pageable next() {
        return null;
    }

    @Override
    public Pageable previousOrFirst() {
        return null;
    }

    @Override
    public Pageable first() {
        return null;
    }

    @Override
    public boolean hasPrevious() {
        return false;
    }
}
